\chapter{Tools}
\label{tools}

In this chapter we provide a description of the tools we have used in the development of HP LIMS. In Sections~\ref{sec:Java} and~\ref{sec:vaadin} we focus on the most important tools used in this thesis, Java and Vaadin. We give a short introduction to Java before digging a little deeper into the world of Vaadin. Section~\ref{sec:otherTools} provides a short description of the other tools used. 

\section{Java}
\label{sec:Java}

Java is an object-oriented programming language developed by Sun Microsystems. Unlike many other programming languages Java is a multi-platform language, meaning that programs written in Java can run on all computers with a Java Virtual Machine (JVM) installed. This is possible due to the fact that Java code is not compiled to machine code, but rather to byte-code which can be run on the JVM, regardless of computer architecture and operating system. Since its release in 1995 Java has grown to be one of the most popular programming languages today. 

Java was chosen for its portability, and we have used Java in the implementation of both the application logic and the user interface code. 

\subsubsection{Java Persistence API}

The Java Persistence API (JPA) is a Java framework used to manage data in Java applications. With this framework it is possible to store (persist) the state of Java objects to a table in a database by defining persistence entities. Persistence entities are typically lightweight Java classes designed purely for holding data. An entity corresponds to a row in a database table. Each entity type (Java class) is persisted to its own database table, and there will typically exist relationships between different types of entities.

\subsubsection{Java Database Connectivity API}

In order to enable Java applications to connect to a database, and thus utilize the Java Persistence API, we have to implement the use of the Java Database Connectivity API (JDBC). Each database requires its own individual JDBC driver to enable the application to connect to the database. Such a JDBC driver is a software component that has to be included in the Java application, enabling the application to interact with the database. The driver will manage the connection to the database, and implements the protocol for transferring the query and result between the application and the database.

There are many different JDBC drivers, each fitting into one of four categories: (1) a JDBC-ODBC bridge, an implementation that employs the ODBC driver to connect to the database by translating JDBC method calls to function calls in ODBC; (2) a Native-API driver, an implementation that makes use of the client side libraries of the database; (3) a Network-Protocol driver, an implementation utilizing middleware (usually an application server) between the application and the database to convert JDBC calls into vendor-specific database calls; or (4) a Native-Protocol Driver, a ``thin'' driver that translates JDBC calls directly to the appropriate vendor-specific database calls. In our implementation we have utilized a JDBC driver fitting into the fourth category, a Native-Protocol driver which converts JDBC calls directly into calls specific for our preferred database implementation. This makes for improved performance, as no translation or middleware is required, but also means that if we want to change our preferred database we also have to replace the JDBC driver.

\section{Vaadin}
\label{sec:vaadin}

Vaadin has already been presented in Sections~\ref{sec:evaluatingJavaFrameworks} and \ref{sec:comparingFrameworks} in comparison to the Play! Framework. In this section we will have a closer look at the key concepts and the basic architecture behind Vaadin.

\begin{quote}
\textit{The key idea in the server-driven programming model of Vaadin is that it lets you forget the web and program user interfaces much like you would program any Java desktop application with conventional toolkits such as AWT, Swing, or SWT. But easier.} \cite{bookOfVaadin}, p. 1.
\end{quote}

With this in mind, it is important to remember how Vaadin should be used and how it should not be used. Vaadin is first and foremost designed to create rich internet applications, applications designed to run in a web browser while still containing the same level of functionality and responsiveness as a regular desktop application. Vaadin is not a tool for creating simple websites.

\subsection{Vaadin architecture}
\label{subsec:architecture}

Figure~\ref{fig:vaadin-architecture} reveals the basic architecture of Vaadin web applications. As described by \citeauthor{bookOfVaadin} \cite{bookOfVaadin}, the architecture of Vaadin consists of two main parts: The server-side framework, Vaadin applications are packaged as a WAR (Web application ARchive) file and are deployed to a Java application server; and the client-side engine. The client-side engine is a JavaScript program running in the web browser which renders the user interface and communicates with the application server, essentially making the web browser a thin client platform.

\begin{figure}[htb]
\centering
\includegraphics[scale=0.2]{figures/vaadin-architecture.eps}
\caption{The basic architecture of Vaadin web applications \cite{bookOfVaadin}. GWT is used along with Vaadin's client-side engine to display the user interface in the web browser. A WAR file containing the Vaadin application servlet is deployed to a Java application server. A Vaadin application operates within the Vaadin application servlet.}
\label{fig:vaadin-architecture}
\end{figure}

\subsubsection{The Vaadin application servlet} A Vaadin application runs as a Java Servlet within a Servlet container on a Java application server. Gr{\"o}nroos \cite{bookOfVaadin} states that everything Vaadin does is done on top of the Java Servlet API. It is only possible to configure one Vaadin application for each Vaadin servlet \cite{learningVaadin}. When starting a new session, a new instance of the application is created. The new application instance is stored on the server until the session is closed, and the framework relays user actions from the client-side to the correct application instance for the duration of the session.

Vaadin is a stateful framework, meaning that the session state is stored on the server. Storing the session state, including UI state, on the server has one major drawback: the application's memory footprint increases with each concurrent session (increasing the risk of an OutOfMemoryError).

\subsubsection{GWT and Ajax} As mentioned previously in Section~\ref{sec:evaluatingJavaFrameworks}, Vaadin combines the use of GWT and Ajax to enable the creation of RIAs. Both of these approaches are well hidden under the hood of Vaadin, freeing the developer from learning JavaScript and worrying about browser support. One of the strengths of GWT is the ability to create advanced user interface components and logic for use within the web browser, which are fully managed by Vaadin's client-side engine. The client-side engine utilizes Ajax techniques to communicate with the server-side framework; the application's logic layer is handled by Vaadin on the server. The biggest difference when developing applications with Vaadin compared to GWT is that with Vaadin developers only write the server-side code, which in turn generates the client-side code.

\subsubsection{Vaadin is event-driven} Vaadin follows the Observer design pattern in order to efficiently communicate user input to the application logic. Other Java-based user interface frameworks, such as Swing or AWT, also utilize the Observer pattern (also known as Event-Listener pattern) for this purpose. With the Observer pattern, illustrated in Figure~\ref{fig:observer}, an object (known as the subject) maintains a list of all objects that depend on the subject. The dependents are known as observers. The subject automatically notifies its observers when the subject's state has changed (known as "firing" an event). In Vaadin, events are usually used to handle user interaction in the user interface, although events can serve all sorts of different purposes. More about the Observer pattern can be found in \cite{Martin:2002}.

\begin{figure}[htb]
\centering
\includegraphics[scale=0.5]{figures/Observer.eps}
\caption{The Observer design pattern. A subject maintains a list of all observers that are waiting for an event from the subject. The subject automatically notifies its observers when the subject's state has changed.}
\label{fig:observer}
\end{figure}

\subsection{Vaadin plug-ins}

Vaadin provides a useful tool for developing applications in the Eclipse IDE. The Vaadin Plug-in for Eclipse provides wizards for creating new projects, widgets and themes, in addition to a visual designer tool where one can design custom views by visually manipulate the size and position of different components. A similiar community created plug-in is available for the NetBeans IDE.

\subsection{Vaadin add-ons}

A key feature with Vaadin is its extendibility. The Vaadin framework comes by default with many useful components and tools, but there are more than 200 official and third-party add-ons available through the Vaadin add-on directory which are very useful when developing applications with Vaadin, ranging from simple themes to data binding implementations.

\subsubsection{Vaadin AppFoundation} The Vaadin AppFoundation is an add-on to the Vaadin framework. It consists of several individual modules designed to simplify the development of Vaadin applications. AppFoundation provides modules for persistence of data, user authentication and authorization, view handling and internationalization, and has been used extensively in the development of HP LIMS.

\section{Other tools}
\label{sec:otherTools}

In addition to the Java programming language and the Vaadin framework, a number of other tools and libraries were necessary in order to create a complete and functional system, including amongst others, a database to store data between sessions, tools for building and managing the project, and server software to run the application. Some of these auxiliary tools will be described below.

\subsection{Database}

We chose to utilize a MySQL database for storage and retrieval of data within our application. MySQL is an open source relational database management system capable of running on several different operating systems and architectures, including, but not limited to, Linux, Mac OS X and Windows. The JDBC driver for Java\footnote{http://dev.mysql.com/usingmysql/java} is a Java library for accessing MySQL databases, and there exists libraries for a number of other programming languages for accessing MySQL databases. MySQL also comes with an ODBC (Open Database Connectivity) interface allowing any programming language supporting the ODBC interface to communicate with a MySQL database. MySQL is capable of handling large amounts of data without slowing the system down as both insert and access times are low. There is a high availability of comprehensive open source tools to help in database administration and in further development of the database schema. 

\subsection{Eclipse IDE}
\label{sec:eclipse}

Eclipse is an integrated development environment (IDE) for developing applications in various programming languages, including, but not limited to, Java, C, C++ and Python.

While there are many development environments to choose from when developing applications in Java, with the availability of the official Vaadin plug-in for Eclipse, Eclipse emerged as the natural choice for developing a Vaadin application.
 
\subsection{Apache Maven}

Maven is an open source tool designed to build and manage Java projects automatically, but it is also possible to use Maven to build and manage projects written in other programming languages, including .NET.

With Maven one can manage a Java project's external dependencies. Maven dynamically downloads Java libraries and Maven plug-ins referenced in the project and builds the application as soon as the dependencies have been resolved and downloaded from one of the many Maven repositories currently in existence, such as the Maven 2 Central Repository. Maven can also be used in consolidation with Eclipse to create a more agile and robust development environment where Maven will manage the project's external dependencies during the implementation process.

\subsection{Apache Tomcat and Jetty}

The Vaadin Servlet needs to be published on a Java web server implementing the Java Servlet container, see Section~\ref{subsec:architecture}. Both Tomcat and Jetty are Java-based open source web servers implementing the Java Servlet container, and are available for both the Windows and Unix platforms.

At a first glance Tomcat and Jetty are rather similar, both being Java application servers implementing the servlet specification, but upon closer inspection they are indeed different. We will not go into much detail about the major and minor differences between the two, or provide detailed performance analyses, but a short summary is useful: Tomcat comes by default as installable software, but can be stripped down to enable embedding in applications, and is first and foremost considered to be an application server. Jetty on the other hand is built on a modular architecture, enabling selection of only the services required, and is both easily embedded in applications and capable of being installed as a stand alone application server. Tomcat is often considered to have slight advantage when it comes to performance, while Jetty usually has better scalability and a smaller memory footprint, in addition to better performance when serving static content \cite{jettyTomcat}.

In the development process both Jetty and Tomcat have been used. Tomcat has been used as the primary application server for deployment, while both Tomcat, set up in the Eclipse workspace, and Jetty, in tight integration with Maven, have been used for application testing before deployment.

\subsection{UniProtJAPI}
\label{sec:uniProtJapi}

The UniProtJAPI library provides a remote API (application programming interface) which enables access to the UniProt databases from external applications \cite{uniProtJapi}. The UniProtJAPI enables the users to blast or search against all the UniProt databases: UniProt KB, UniParc, UniRef or UniMes (see Chapter~\ref{sec:uniProt} for details about the UniProt databases).

UniProt also provides a REST (Representational state transfer) API\footnote{The UniProt REST API documentation is available at http://www.uniprot.org/faq/28} which enables access to both individual entries and sets of entries through simple URLs. Some drawbacks with using this approach is that it is not possible to BLAST sequences and it is cumbersome to parse the results returned, especially when data formats can be subject to frequent change. With the UniProtJAPI the drawbacks connected to the REST API are diminished, as the need for system maintenance in bioinformatics applications is mitigated when all the internal format changes are wrapped in the UniProtJAPI objects, and the information is no longer parsed manually.

The UniProtJAPI is available through the UniProtJAPI Archive\footnote{http://www.ebi.ac.uk/uniprot/remotingAPI/archive.html} or through EBI's Maven repository. Each major release of the UniProtJAPI has a guaranteed stable data source for at least two years after the release.

\subsection{Apache POI}

Apache POI is a project from the Apache Foundation that provides pure Java libraries enabling reading of and writing to files in several formats used in the Microsoft Office packages. The Apache POI project provides Java APIs that simplifies writing to and reading from many different file formats, including files based on the Office Open XML standards (OOXML) and Microsoft's OLE2 Compound Document format (OLE2).

File formats that belong to OLE2 are formats such as XLS (Excel), DOC (Word), and PPT (Powerpoint). OOXML is a standard based on XML, and is found in Microsoft Office 2007 and newer versions. File formats belonging to this standard include XLSX, DOCX, and PPTX.

\subsection{iText}

iText is a library available in Java and C\# allowing the user to create, extract information from, and manipulate PDF documents. It provides a means of enriching applications with the ability to generate dynamic PDF documents.

\section{Summary}

In this chapter we have presented the most important tools and technologies employed in the development of HP LIMS. We have utilized Java as the main programming language, and the implementation of the application has been based on the Vaadin framework. Other tools applied in the development process are the UniProtJAPI, which has provided BLAST search support to the application; a MySQL database, for storage and retrieval of data; Apache Maven, our build automation tool; and Apache Tomcat and Jetty, the application servers used for deployment and testing of the application.